package com.zyh.controller;

import com.zyh.pojo.Post;
import com.zyh.service.FollowService;
import com.zyh.service.PostService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class MentionController {
    @Autowired
    FollowService followService;
    @Autowired
    PostService postService;
    @GetMapping("/mentions/{username}")
    public String mentions(@PathVariable String username, Model model){
        model.addAttribute("username",username);
        String loginUserName= (String) SecurityUtils.getSubject().getPrincipal();
        List<Post> posts=postService.findMentionsByName(username);
        model.addAttribute("posts",posts);
        if(!loginUserName.equals(username))//访问别人的mention
        {
            model.addAttribute("isfollowing",followService.judgeFollow(loginUserName,username));
        }
        return "mentions";
    }
}
